function extendAPIOutput(req, res, next) {
  res.apiSuccess = function (data) {
    res.json({
      status: 'ok', result: data,code:200
    });
  };
  res.apiError = function (err) {
    res.json({
      status: 'Error',code:404,
      error_code: err.error_code || 'UNKNOWN',
      error_message: err.error_code || err.toString()
    });
  }
  next();
}
function createApiError(code, msg) {
  var err=new Error(msg);
  err.error_code=code;
  err.error_message=msg;
  return err;
}

function apiErrorHandle(err,req,res,next){
  if(typeof res.apiError==='function'){
    return res.apiError(err)
  }
  next();
}
module.exports = extendAPIOutput;